package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.hjq.bar.TitleBar;
import com.hjq.base.BaseAdapter;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.bean.MessBean;
import com.jjb.www.http.api.CertificateNoticeApi;
import com.jjb.www.http.api.CurriculumSortApi;
import com.jjb.www.http.api.HomePosterApi;
import com.jjb.www.http.api.MeCertificateApi;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.adapter.HomeMessageAdapter;
import com.jjb.www.ui.adapter.MeCertificateAdapter;
import com.jjb.www.ui.fragment.CourseListFragment;
import com.jjb.www.widget.ScrollingTextView;
import com.xj.marqueeview.MarqueeView;

import java.util.ArrayList;
import java.util.List;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/03/01
 *    desc   : 我的证书
 */
public class MeCertificateActivity extends AppActivity implements BaseAdapter.OnItemClickListener {
    private TitleBar mTitleBar;
    private WrapRecyclerView mRvMeCert;
    private MeCertificateAdapter adapter;
    private ScrollingTextView mTvMessage;





    @Override
    protected int getLayoutId() {
        return R.layout.activity_me_certificate;
    }

    @Override
    protected void initView() {
        mTvMessage = findViewById(R.id.tv_message);
        mTitleBar = findViewById(R.id.titleBar);
        mRvMeCert = findViewById(R.id.rv_me_cert);
        mRvMeCert.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new MeCertificateAdapter(getContext());
        adapter.setOnItemClickListener(this);
        mRvMeCert.setAdapter(adapter);

    }

    @Override
    protected void initData() {
       getList();
       getNotice();
    }

    private void getNotice() {
        EasyHttp.get(this)
                .api(new CertificateNoticeApi())
                .request(new HttpCallback<HttpData<CertificateNoticeApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<CertificateNoticeApi.Bean> data) {
                        mTvMessage.setText(data.getData().getNotice());
                    }

                });
    }

    private void getList() {
        EasyHttp.get(this)
                .api(new MeCertificateApi())
                .request(new HttpCallback<HttpList<MeCertificateApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpList<MeCertificateApi.Bean> data) {
                        mTitleBar.setTitle("我的证书("+data.getData().size()+")");
                        adapter.setData(data.getData());
                    }

                });
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        Intent intent = new Intent();
        intent.putExtra("cert_num",adapter.getItem(position).getId()+"");
        intent.setClass(getContext(),CertificateDetailsActivity.class);
        startActivity(intent);
    }
}